package com.example.moduletwo.adapter;

import android.content.Context;
import android.view.View;

import com.example.baselibrary.util.LKToastUtil;
import com.example.moduletwo.R;
import com.example.moduletwo.adapter.binder.TestTwoAdapterBinder1;
import com.example.moduletwo.adapter.binder.TestTwoAdapterBinder5;
import com.example.moduletwo.adapter.delegate.TestTwoAdapterDelegate1;
import com.example.moduletwo.adapter.delegate.TestTwoAdapterDelegate5;
import com.example.moduletwo.bean.BeanTwo;
import com.example.mvp.adapter.BaseLibMultipleViewAdapter;
import com.example.mvp.binder.BaseDataBinder;
import com.example.mvp.delegate.BaseAdapterDelegate;

import java.util.List;

/**
 * 测试适配器操作处理类
 * Created by sun.li on 2018/6/6.
 *
 * @author sun.li
 */

public class TestThreeAdapter extends BaseLibMultipleViewAdapter<BeanTwo> {

    public TestThreeAdapter(Context context, List<BeanTwo> mList) {
        super(context, mList);
    }

    @Override
    protected void bindEvenListener(BaseAdapterDelegate viewDelegate,  int position) {
//        int index = position+1;
//        if(index%3==0){
//            itemOnClickListener3(viewDelegate,position);
//        }else if(index%2==0){
//            itemOnClickListener2(viewDelegate,position);

//        }else{
            itemOnClickListener1(viewDelegate,position);
//        }

    }

    private void itemOnClickListener1(final BaseAdapterDelegate viewDelegate, final int position) {
        viewDelegate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(null!=getData()){
                    BeanTwo beanTwo = getData().get(position);
                    String str = beanTwo.getStr1();
                    LKToastUtil.showToastShort(str+"_one");
                    beanTwo.setStr1(str+"_"+v.getId());
                    getData().set(position,beanTwo);
                    notifyDataSetChanged();
//                    ((TestTwoAdapterDelegate1)viewDelegate).setText(str+"_"+v.getId()+"_one");
                }

            }
        }, R.id.tv_ati1_text);
    }

    private void itemOnClickListener2(BaseAdapterDelegate viewDelegate, final int position) {
        viewDelegate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(null!=getData()){
                    BeanTwo beanTwo = getData().get(position);
                    String str = beanTwo.getStr1();
                    LKToastUtil.showToastShort(str+"_two");
                    beanTwo.setStr1(str+"_"+v.getId());
                    getData().set(position,beanTwo);
                    notifyDataSetChanged();
                }

            }
        }, R.id.tv_ati2_text);
    }

    private void itemOnClickListener3(BaseAdapterDelegate viewDelegate, final int position) {
        viewDelegate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(null!=getData()){
                    BeanTwo beanTwo = getData().get(position);
                    String str = beanTwo.getStr1();
                    LKToastUtil.showToastShort(str+"_three");
                    beanTwo.setStr1(str+"_"+v.getId());
                    getData().set(position,beanTwo);
                    notifyDataSetChanged();
                }
            }
        }, R.id.tv_ati3_text);
    }

    @Override
    protected void notifyView(BaseAdapterDelegate viewDelegate,  int position) {
//        viewDelegate.setText(getData().get(position));
    }

    @Override
    public BaseAdapterDelegate getDelegate(int position) {
        BaseAdapterDelegate baseAdapterDelegate = null;
        int index = position+1;
        if(index%5==0){
            try {
                baseAdapterDelegate = TestTwoAdapterDelegate5.class.newInstance();
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
//        }else if(index%3==0){
//            try {
//                baseAdapterDelegate = TestTwoAdapterDelegate3.class.newInstance();
//            } catch (InstantiationException e) {
//                e.printStackTrace();
//            } catch (IllegalAccessException e) {
//                e.printStackTrace();
//            }
//        }else if(index%2==0){
//            try {
//                baseAdapterDelegate = TestTwoAdapterDelegate2.class.newInstance();
//            } catch (InstantiationException e) {
//                e.printStackTrace();
//            } catch (IllegalAccessException e) {
//                e.printStackTrace();
//            }
        }else{
            try {
                baseAdapterDelegate = TestTwoAdapterDelegate1.class.newInstance();
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
        return baseAdapterDelegate;
    }


    @Override
    public BaseDataBinder getDataBinder(int position) {
        BaseDataBinder baseAdapterDataBinder;
        int index = position+1;
        if(index%5==0){
            baseAdapterDataBinder = new TestTwoAdapterBinder5();
//        }else if(index%3==0){
//            baseAdapterDataBinder = new TestTwoAdapterBinder3();
//        }else if(index%2==0){
//            baseAdapterDataBinder = new TestTwoAdapterBinder2();
        }else{
            baseAdapterDataBinder = new TestTwoAdapterBinder1();
        }
        return baseAdapterDataBinder;
    }

    @Override
    public Object getItemData(int position) {
        int index = position+1;
        if(index%5==0){
            return getData().get(position).getBeanFive();
        }else{
            return getData().get(position).getStr1();
        }
    }

}
